package com.woniuxy.controller;



import com.woniuxy.common.Result;
import com.woniuxy.controller.form.AddFoodTypeForm;
import com.woniuxy.controller.form.ChangeFoodTypeStateForm;
import com.woniuxy.entity.FoodType;
import com.woniuxy.service.FoodTypeService;
import com.woniuxy.service.dto.FoodParentTypeDto;
import com.woniuxy.service.dto.FoodTypeDto;
import com.woniuxy.service.dto.FoodTypeTreeDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * <p>
 * 菜品类型表 前端控制器
 * </p>
 *
 * @author zz
 * @since 2023年06月13日
 */
@RestController
@RequestMapping("/foodType")
@Api(tags = "食物类型模块相关接口")
public class FoodTypeController {

    @Autowired
    private FoodTypeService foodTypeService;

    @ApiOperation("新增食物类型")
    @PostMapping("/addFoodType")
    public Result addBookType(@Valid  @RequestBody AddFoodTypeForm addFoodTypeForm) throws Exception {
        FoodType foodType = foodTypeService.addFoodType(addFoodTypeForm);
        return Result.success(200, "新增食品类型成功",foodType );
    }

    @ApiOperation("上架/下架/删除食物类型")
    @PutMapping("/changeFoodTypeState")
    public Result changeFoodType(@Valid @RequestBody ChangeFoodTypeStateForm form ) throws Exception {
        foodTypeService.changeFoodeTypeState(form);
        return Result.success(200,"修改类型状态成功",null);
    }


    @ApiOperation("展示所有食品类型")
    @GetMapping("/showFoodTypeTree")
    public Result showFoodTypeTree() throws Exception{
        List<FoodTypeTreeDto> list = foodTypeService.showFoodTypeTree();
        return Result.success(200,"获取所有食品类型成功",list);
    }

    @ApiOperation("展示所有父节点类型")
    @GetMapping("/showParentTypeTree")
    public Result showParentTypeTree() throws Exception{
        List<FoodParentTypeDto> list = foodTypeService.showParentTypeTree();
        return Result.success(200,"获取所有父级类型成功",list);
    }


    @ApiOperation("展示所有最终食品类型")
    @GetMapping("/showNodeTypeTree")
    public Result showFoodNodeType() throws Exception{
        List<FoodTypeDto> list = foodTypeService.showFoodNodeType();
        return Result.success(200,"获取所有最终食品类型成功",list);
    }


}

